package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cnzz.site1255174697.R;
import com.cqyanyu.yanyu.view.FontIconView;
import com.cqyanyu.yanyu.view.XBaseViewHolder;

/**
 * 宫格按钮适配器
 * 1.图文宫格
 * 2.图片宫格
 */
public class BaseImgTGridAdapter extends BaseAdapter {

    private Context context;
    private String[] name;
    private int[] img;

    public BaseImgTGridAdapter(Context context, String[] name, int[] img) {
        this.context = context;
        this.name = name;
        this.img = img;
    }

    @Override
    public int getCount() {
        if (name.length < 0) {
            return 0;
        }
        return name.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_text_img, null);
        }
        FontIconView xyImage = XBaseViewHolder.get(convertView, R.id.xy_image);
        TextView xyTitle = XBaseViewHolder.get(convertView, R.id.xy_title);
        if (img.length > 0 && img != null) {
            xyImage.setText(img[position]);
        }
        if (name.length > 0) {
            xyTitle.setText(name[position]);
        }
        return convertView;
    }
}
